---
layout: default
---
<div class="home">
  <section>
    <div class="row">
      <div class="small-6 columns">
        <h2>Usage</h2>
      </div>
      <div class="small-6 columns text-right"></div>
    </div>
    <div class="row">
      <div class="large-12 columns">
        <p>Create a seed file (eg. <code class="highlight">/path/to/seeds/20150928000000_initial_seed.rb</code>)</p>
<pre class="highlight">
<span class="nc">Sequel</span>.seed(<span class="vi">:development</span>, <span class="vi">:test</span>) <span class="kc">do</span> <span class="c"># Applies only to "development" and "test" environments</span>
  <span class="kc">def</span> run
    <span class="nc">User</span>.create \
      <span class="vi">full_name:</span> <span class="s">"Richard Feynman"</span>,
      <span class="vi">profession:</span> <span class="s">"Theoretical physicist"</span>,
      <span class="vi">username:</span> <span class="s">"rfeynman"</span>,
      <span class="vi">password:</span> <span class="s">"271828"</span>
  <span class="kc">end</span>
<span class="kc">end</span>

<span class="nc">Sequel</span>.seed <span class="kc">do</span> <span class="c"># Wildcard Seed; applies to every environment</span>
  <span class="kc">def</span> run
    [
      [<span class="s">'USD'</span>, <span class="s">'United States dollar'</span>],
      [<span class="s">'BRL'</span>, <span class="s">'Brazilian real'</span>]
    ].each <span class="kc">do</span> |abbr, name|
      <span class="nc">Currency</span>.create <span class="vi">abbr:</span> abbr, <span class="vi">name:</span> name
    <span class="kc">end</span>
  <span class="kc">end</span>
<span class="kc">end</span>
</pre>
        <p>Set the environment (optional &mdash; if omitted, it will fulfil wildcard Seeds only)</p>
<pre class="highlight">
<span class="nc">Sequel</span>::<span class="nc">Seed</span>.setup(<span class="vi">:development</span>)
</pre>
        <p>Load the extension</p>
<pre class="highlight">
<span class="nf">require</span> <span class="s">'sequel'</span>
<span class="nf">require</span> <span class="s">'sequel/extensions/seed'</span>

<span class="nc">Sequel</span>.extension <span class="vi">:seed</span>
</pre>
        <p>Apply the seeds/fixtures</p>
<pre class="highlight">
<span class="nc">DB</span> = Sequel.connect(...)
<span class="nc">Sequel</span>::<span class="nc">Seeder</span>.apply(<span class="nc">DB</span>, <span class="s">"/path/to/seeds"</span>)
</pre>
      </div>
    </div>
  </section>
  <section class="row">
    <div class="large-12 columns">
      <h2>Limitations</h2>
      <ul>
        <li>JSON and YAML files don't work with associations</li>
        <li>Only timestamped fixture/seed files by now</li>
      </ul>
    </div>
  </section>
  <section class="row">
    <div class="large-12 columns">
      <h2>What's next?</h2>
      <p>Work with Model's associations inside JSON &amp; YAML files</p>
    </div>
  </section>
  <section class="row">
    <div class="large-12 columns">
      <h2>Support &amp; Documentation</h2>
      <p>If you need any help (or have found any bug &#x1f41e;), please post it on
<a href="//github.com/earaujoassis/sequel-seed/issues">/issues</a>. Check out the <a href="{{ "/documentation" | prepend: site.baseurl }}">documentation</a> if you need help on how
to create seed/fixture files using Ruby, YAML and JSON code and how to apply them over a database instance.</p>
    </div>
  </section>
</div>
